package com.yixing.tech.wms.controller;

import com.yixing.tech.common.base.BaseControl;
import com.yixing.tech.common.base.BusinessException;
import com.yixing.tech.common.base.Rs;
import com.yixing.tech.wms.param.ContainerBindMaterialParam;
import com.yixing.tech.wms.param.ContainerByLocationParam;
import com.yixing.tech.wms.param.RawMaterialApplyContainerParam;
import com.yixing.tech.wms.param.ToApplyParam;
import com.yixing.tech.wms.service.impl.SalesReturnStockServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 销售退库
 *
 * @author yixing tech
 * @since 1.0.0
 */
@RestController
@CrossOrigin
@RequestMapping(value = "/sales/return")
public class SalesReturnStockController extends BaseControl {

    @Autowired
    private SalesReturnStockServiceImpl salesReturnStockService;

    /**
     * 待申请容器的入库单列表V2
     */
    @PostMapping("/list/toApply/v2")
    public Rs<Object> listToApply(@RequestBody ToApplyParam param) throws BusinessException {
        return Rs.ok(salesReturnStockService.listToApplyParam(param));
    }

    /**
     * 查看申请成功的入库单明细
     */
    @PostMapping("/list/inStoking")
    public Rs<Object> listInStoking(@RequestBody ToApplyParam param) throws BusinessException {
        return Rs.ok(salesReturnStockService.listInStoking(param));
    }

    /**
     * 申请容器
     */
    @PostMapping("/applyContainer")
    public Rs<Object> applyContainer(@RequestBody RawMaterialApplyContainerParam param) throws BusinessException {
        return Rs.ok(salesReturnStockService.applyContainerByInOrders(param.getInOrders(), param.getAbc()));
    }

    /**
     * 查询容器带绑定的信息
     */
    @PostMapping("/find/containerToBind")
    public Rs<Object> findContainerToBind(@RequestBody ContainerBindMaterialParam param) throws BusinessException {
        return Rs.ok(salesReturnStockService.findContainerToBind(param.getContainerCode()));
    }

    /**
     * 查询容器带绑定的信息，通过库位
     */
    @PostMapping("/find/containerToBind/byLocation")
    public Rs<Object> findContainerToBindByLocation(@RequestBody ContainerByLocationParam param) throws BusinessException {
        return Rs.ok(salesReturnStockService.findContainerToBindByLocation(param.getLocationCode()));
    }

    /**
     * 查询容器带绑定
     */
    @PostMapping("/find/containerToBind/byId")
    public Rs<Object> findContainerToBindById(@RequestBody ContainerBindMaterialParam param) throws BusinessException {
        return Rs.ok(salesReturnStockService.findContainerToBindById(param.getBindId()));
    }

    /**
     * 绑定物料到容器，申请库位，启动入库
     */
    @PostMapping("/start/inStock")
    public Rs<Object> startStock(@RequestBody ContainerBindMaterialParam param) throws BusinessException {
        return Rs.ok(salesReturnStockService.startStock(param));
    }

    /**
     * 申请库位
     */
    @PostMapping("/applyLocation")
    public Rs<Object> applyLocationByContainerCode(@RequestBody ContainerBindMaterialParam param) throws BusinessException {
        return Rs.ok(salesReturnStockService.applyLocationByContainerCode(param.getContainerCode()));
    }

    /**
     * 上报Erp
     */
    @PostMapping("/report/erp/{dtlId}")
    public Rs<Object> reportErp(@PathVariable("dtlId") String dtlId) throws BusinessException {
        return Rs.ok(salesReturnStockService.reportErp(dtlId));
    }


}
